package com.aaa.system.controller.api;
import com.aaa.security.annotation.HasPermission;
import com.aaa.security.annotation.MyLog;
import com.aaa.system.service.MenuService;
import com.aaa.system.service.RoleService;
import com.aaa.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.aaa.entity.Role;


@Api("system/api/RoleController")
@RestController
@RequestMapping("system/api/RoleController")
public class ApiRoleController {
    @Autowired
    private RoleService roleService;
    @Autowired
    private MenuService menuService;

    /**
     * @author JYH
     * @date 2023/3/3 11:47
     * @description -
     * @param currentPage
     * @param pageSize
     * @param role
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "currentPage", value = "", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "", required = true),
            @ApiImplicitParam(paramType = "body", dataType = "Role", name = "role", value = "", required = true)
    })
    @ApiOperation(value = "-", notes = "-")
    @MyLog(title="查询所有角色")
    @RequestMapping("selectAll")
    public Result selectAll(@RequestParam(defaultValue = "1")Integer currentPage,
                            @RequestParam(defaultValue = "5")Integer pageSize,
                            @RequestBody Role role){
        return roleService.selectAll(currentPage,pageSize,role);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "roleId", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "")
    @MyLog(title="删除角色")
    @RequestMapping("delete")
    public Result delete(Integer roleId){
        return roleService.delete(roleId);
    }
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Role", name = "role", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "")
    @MyLog(title="更新角色")
    @RequestMapping("update")
    public Result update(@RequestBody Role role){
        return roleService.update(role);
    }
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Role", name = "role", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "")
    @MyLog(title="添加角色")
    @RequestMapping("insert")
    @HasPermission(value = "role:insert")
    public Result insert(@RequestBody Role role){
        return roleService.insert(role);
    }

    //菜单权限查询
    @ApiOperation(value = "菜单权限查询", notes = "菜单权限查询")
    @RequestMapping("queryAllTreeData")
    public Result queryAllTreeData(){
        return menuService.selectAll();
    }

    /**
     *
     * @author JYH
     * @date 2023/3/1 14:30
     * @description
     roleId
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "roleId", value = "", required = true)
    })
    @ApiOperation(value = "roleId", notes = "roleId", httpMethod = "GET")
    @GetMapping("/queryMenusByRoleId")
    public Result queryMenusByRoleId(Integer roleId){
        return roleService.queryMenusByRoleId(roleId);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "roleId", value = "", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String[]", name = "menuIds", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("/batchInsertRoleMenu")
    public Result batchInsertRoleMenu(Integer roleId,String[] menuIds){
        return roleService.batchInsertRoleMenu(roleId,menuIds);
    }
}
